package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.guoguojie.dao.FamilyTagDao;
import cn.sumpu.app.guoguojie.domain.FamilyTag;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class FamilyTagDaoImpl extends SqlSessionDaoSupport implements FamilyTagDao {

	private static Logger logger = LoggerFactory.getLogger(FamilyTagDaoImpl.class);

	public void insertFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		try {
			getSqlSession().insert(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.insert",
					familyTag);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertFamilyTag database failure.", e);
			}
			throw new AppBusinessException("insertFamilyTag database failure.", e);
		}
	}

	public void deleteFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		try {
			getSqlSession().delete(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.delete",
					familyTag);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteFamilyTag database failure.", e);
			}
			throw new AppBusinessException("deleteFamilyTag database failure.", e);
		}
	}
	
	public void deleteFamilyTagByFamily(String doorplate) throws AppBusinessException {
		try {
			getSqlSession().delete(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.deleteByFamily",
					doorplate);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteFamilyTagByFamily database failure.", e);
			}
			throw new AppBusinessException("deleteFamilyTagByFamily database failure.", e);
		}
	}

	public void updateFamilyTag(FamilyTag familyTag) throws AppBusinessException {
		try {
			getSqlSession().update(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.update",
					familyTag);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateFamilyTag database failure.", e);
			}
			throw new AppBusinessException("updateFamilyTag database failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	public List<FamilyTag> getFamilyTagList(Map<String, Object> map) throws AppBusinessException {
		try {
			return  getSqlSession().selectList(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.getFamilyTagList",
					map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFamilyTagList database failure.", e);
			}
			throw new AppBusinessException("getFamilyTagList database failure.", e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<FamilyTag> getFamilyTagByDoorplate(String doorplate) throws AppBusinessException {
		try {
			return  getSqlSession().selectList(
					"cn.sumpu.app.guoguojie.persistence.FamilyTagMapper.getFamilyTagByDoorplate",
					doorplate);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFamilyTagByDoorplate database failure.", e);
			}
			throw new AppBusinessException("getFamilyTagByDoorplate database failure.", e);
		}
	}

}
